package com.bite.book.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

//进行统计每个方法消耗的时间；
@Slf4j
@Aspect
@Component
public class TimeAspect {
    @Around("execution(* com.bite.book.controller.*.*(..))")
    public Object timeRecord(ProceedingJoinPoint pjp) throws Throwable {
        //1,进行记录开始的时间；
        long start = System.currentTimeMillis();
        //2，进行执行相关的目标方法；
        Object proceed =pjp.proceed();
        long end=System.currentTimeMillis();
        log.info(pjp.getSignature().toString()+"耗时："+(end-start)+"ms");
        return proceed;
    }
}